<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #box {
        border: 6px solid;
        width: 400px;
        height: 400px;
        overflow: auto;
      }

      #box p {
        height: 100px;
        border: solid;
      }
      p,
      body {
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
    <div id="box">
      <p>hello p1</p>
      <p>hello p2</p>
      <p>hello p3</p>
      <p>hello p4</p>
      <p>hello p5</p>
      <p>hello p6</p>
      <p>hello p7</p>
      <p>hello p8</p>
    </div>
    <script>
      const box = document.getElementById("box");
      setTimeout(() => {
        const scrollHeight = box.scrollHeight;
        const scrollTop = box.scrollTop;
        const clientHeight = box.clientHeight;

        // 一般是流出一个安全距离，小于安全距离表示触底
        console.log(scrollHeight - scrollTop - clientHeight < 30);
      }, 3000);
    </script>
  </body>
</html>
